﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestLoadDependon : MonoBehaviour
{
    // Start is called before the first frame update
    IEnumerator Start()
    {
        AssetBundle depenon = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/StreamingAssets");

        AssetBundleManifest manifest = depenon.LoadAsset<AssetBundleManifest>("AssetBundleManifest");

        string[] dependons = manifest.GetAllDependencies("ui.unity3d");

        AssetBundle texture = null;

        for (int i = 0; i < dependons.Length; i++)
        {
            Debug.LogFormat("ui dependon : {0}", dependons[i]);
            texture = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + dependons[i]);
        }

        AssetBundle assetBundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/ui.unity3d");
        if (assetBundle != null)
        {
            Debug.Log("加载成功!");
            GameObject objectPrefab = assetBundle.LoadAsset<GameObject>("TestPanel");
            GameObject.Instantiate(objectPrefab, transform);

        }

        yield return new WaitForSeconds(2);

        texture.Unload(true);

    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
